package com.hexm.sudokuweb.sudoku.util;

import java.util.Arrays;

/**
 * @Classname SudokuUtil
 * @Description TODO
 * @Date 2021/2/13 13:19
 * @Created by hexm
 */
public class SudokuUtil {

    /**
     * 二维数组克隆
     * @param param
     * @return
     */
    public static int[][] dataCopy(int[][] param) {
        int[][] array = new int[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                array[i][j] = param[i][j];
            }
        }
        return array;
    }

    /**
     * 打印
     */
    public static void print(int[][] data) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                System.out.print(data[i][j] + "  ");
                if (j == 8) {
                    System.out.println();
                }
            }
        }
    }

    /**
     * 二维数组是否相同
     *
     * @param arr1
     * @param arr2
     * @return
     */
    public static boolean arrayEquals(final int[][] arr1, final int[][] arr2) {
        if (arr1 == null) {
            return (arr2 == null);
        }
        if (arr2 == null) {
            return false;
        }
        if (arr1.length != arr2.length) {
            return false;
        }
        for (int i = 0; i < arr1.length; i++) {
            if (!Arrays.equals(arr1[i], arr2[i])) {
                return false;
            }
        }
        return true;
    }
}
